package com.example.studycode

import android.os.Bundle
import android.view.View
import android.widget.ScrollView
import android.widget.ImageButton
import androidx.appcompat.app.AppCompatActivity

class ScrollView : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_scroll_view)

        val scrollView = findViewById<ScrollView>(R.id.scrollView)
        val backToTopButton = findViewById<ImageButton>(R.id.backToTopButton)

        scrollView.viewTreeObserver.addOnScrollChangedListener {
            if (scrollView.scrollY > 100) {
                backToTopButton.visibility = View.VISIBLE
            } else {
                backToTopButton.visibility = View.GONE
            }
        }
    }

    fun scrollToTop(view: View) {
        val scrollView = findViewById<ScrollView>(R.id.scrollView)
        scrollView.smoothScrollTo(0, 0)
    }
}
